package com.css.fxfzypg.modules.model.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.model.entity.Material;
import com.css.fxfzypg.modules.model.service.MaterialService;
import com.css.fxfzypg.modules.model.vo.IntensityAttenuationVO;
import com.css.fxfzypg.modules.model.vo.MaterialVO;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.ResponseCreator;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Map;

/**
 * @author Dbj
 * @date 2022年10月05日  17:28
 * 物资需求评估模型
 */
@RestController
@Validated
@RequestMapping("/material")
public class MaterialController {

    @Resource
    private MaterialService materialService;
    /***
     * 物资需求评估模型列表分页查询
     * @param vo
     */
    @GetMapping("/page")
    public RestResponse getPage(MaterialVO vo, HttpServletRequest request){
        int curPage = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int pageSize=Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        Map<String,Object> page=materialService.getPage(vo,curPage,pageSize);
        return ResponseCreator.createSuccessResponse(page,"查询成功!");
    }

    /***
     * 物资需求评估模型根据模型id查询信息
     * @param id
     */
    @GetMapping("/getModelById")
    public RestResponse getModelById(@NotBlank(message="模型id不能为空") @RequestParam("id") String id){
        Material model = materialService.getModelById(id);
        return ResponseCreator.createSuccessResponse(model);
    }

    /***
     *  物资需求评估模型id查询信息用于复制信息回显
     * @param id
     */
    @GetMapping("/getModelByIdForCopy")
    public RestResponse getModelByIdForCopy(@NotBlank(message="模型id不能为空") @RequestParam("id") String id){
        Material model = materialService.getModelByIdForCopy(id);
        return ResponseCreator.createSuccessResponse(model);
    }

    /***
     * 物资需求评估模型-用于复制保存
     * @param material
     */
    @PostMapping("/save")
    public RestResponse saveIntensityAttenuation(@Valid @RequestBody Material material){
        materialService.save(material);
        return ResponseCreator.createSuccessResponse("","保存成功");
    }

    /***
     * 物资需求评估模型-修改
     * @param material
     */
    @PostMapping("/update")
    public RestResponse update(@Valid @RequestBody Material material){
        materialService.update(material);
        return ResponseCreator.createSuccessResponse("","保存成功");
    }

    /***
     * 物资需求评估模型-删除
     * @param vo
     */
    @PostMapping("/delete")
    public RestResponse delete(@RequestBody MaterialVO vo){
        materialService.delete(vo.getId());
        return ResponseCreator.createSuccessResponse("","删除成功");
    }
}
